﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aij1.BLL;
using Aij1.Model;
using Aij1.Utils;
using DevExpress.Web.ASPxGridView;

namespace Aij1.Cms
{
    public partial class NewsMan : AdminPage
    {
        int catId;
        protected void Page_Load(object sender, EventArgs e)
        {
            GridViewDataComboBoxColumn col = ASPxGridView1.Columns["colStatus"] as GridViewDataComboBoxColumn;
            col.PropertiesComboBox.DataSource = CategoryData.GetTypes<ArticleStatusType>();
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            catId = CommOp.ToInt(Request.Form["CategoryId"]);
            if (catId > 0)
            {
                XpoDataSource1.Criteria = String.Format("CategoryId={0} AND AType=0", catId);
                ASPxGridView1.Caption = XpoSession.GetObjectByKey<A_Category>(catId).Title;
            }
            XpoDataSource1.Session = XpoSession;
            XpoDataSource2.Session = XpoSession;
        }

        protected void ASPxGridView1_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
        {
            string[] ops = e.Parameters.Split(':');
            if (ops.Length >= 2)
            {
                string op = ops[0];
                string ids = ops[1];
                switch (op)
                {
                    case "settop":
                        ArticleData.SetTop(XpoSession, ids);
                        break;
                    case "canceltop":
                        ArticleData.UnsetTop(XpoSession, ids);
                        break;
                    case "del":
                        ArticleData.Delete(XpoSession, ids);
                        break;
                    default:
                        break;
                }
            }
            ASPxGridView1.DataBind();
        }

        protected void ASPxGridView1_HtmlRowPrepared(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
        {
            if (e.RowType != GridViewRowType.Data) return;
            A_Article art = ASPxGridView1.GetRow(e.VisibleIndex) as A_Article;
            //置顶的行高亮显示
            if (art.SetTopTime != default(DateTime))
            {
                e.Row.Style.Add("background", "#ddd");
            }
        }
    }
}